package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2023-12-03  21:23
 */
public class ThreadDemo19 {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread thread1 = new Thread(() -> {
            synchronized(locker) {
                System.out.println("执行wait之前！");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("执行wait之后！");
            }
        });
        Thread thread2 = new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized(locker) {
                System.out.println("执行notify之前！");
                locker.notify();
                System.out.println("执行notify之后！");
            }
        });
        thread1.start();
        thread2.start();
    }
}
